package com.ruoyi.project.wodemand.controller;

import java.util.List;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.framework.security.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wodemand.domain.TInfoSheettype;
import com.ruoyi.project.wodemand.service.ITInfoSheettypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 工单类型Controller
 *
 * @author lt
 * @date 2020-04-14
 */
@RestController
@RequestMapping("/wodemand/SHEETTYPE")
public class TInfoSheettypeController extends BaseController
{
    @Autowired
    private ITInfoSheettypeService tInfoSheettypeService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询工单类型列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInfoSheettype tInfoSheettype)
    {
        startPage();
        List<TInfoSheettype> list = tInfoSheettypeService.selectTInfoSheettypeList(tInfoSheettype);
        return getDataTable(list);
    }

    /**
     * 导出工单类型列表
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:export')")
    @Log(title = "工单类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TInfoSheettype tInfoSheettype)
    {
        List<TInfoSheettype> list = tInfoSheettypeService.selectTInfoSheettypeList(tInfoSheettype);
        ExcelUtil<TInfoSheettype> util = new ExcelUtil<TInfoSheettype>(TInfoSheettype.class);
        return util.exportExcel(list, "SHEETTYPE");
    }

    /**
     * 获取工单类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:query')")
    @GetMapping(value = "/{sheetTypeId}")
    public AjaxResult getInfo(@PathVariable("sheetTypeId") String sheetTypeId)
    {
        return AjaxResult.success(tInfoSheettypeService.selectTInfoSheettypeById(sheetTypeId));
    }

    /**
     * 新增工单类型
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:add')")
    @Log(title = "工单类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInfoSheettype tInfoSheettype)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        tInfoSheettype.setDealStaffId(operName);
        tInfoSheettype.setAuditNode1("1");
        tInfoSheettype.setAuditNode2("2");
        return toAjax(tInfoSheettypeService.insertTInfoSheettype(tInfoSheettype));
    }

    /**
     * 修改工单类型
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:edit')")
    @Log(title = "工单类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInfoSheettype tInfoSheettype)
    {
        return toAjax(tInfoSheettypeService.updateTInfoSheettype(tInfoSheettype));
    }

    /**
     * 删除工单类型
     */
    @PreAuthorize("@ss.hasPermi('wodemand:SHEETTYPE:remove')")
    @Log(title = "工单类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sheetTypeIds}")
    public AjaxResult remove(@PathVariable String[] sheetTypeIds)
    {
        return toAjax(tInfoSheettypeService.deleteTInfoSheettypeByIds(sheetTypeIds));
    }


}
